# 一、定义一个狗类,里面有一个 列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
#        实现狗的买卖交易方法;  打印输出经过2-3次买卖方法后,剩下的各类狗的数量;

class Dog:
    list1 = [{"colour": "red", "sum": 3, "price": 5},
             {"colour": "yellow", "sum": 4, "price": 3},
             {"colour": "black", "sum": 2, "price": 10}]

    def buy(self, x):
        for i in range(0, 3):
            if self.list1[i]['colour'] == x and self.list1[i]['sum'] > 0:
                self.list1[i]['sum'] = self.list1[i]['sum'] - 1

    def p(self):
        print(self.list1)


A = Dog()
A.p()
A.buy('black')
A.p()
